<?php

namespace App\Models;

use Carbon\Carbon;

class UserAddress extends Model
{
    protected $guarded = ['user_id'];

    protected $dates = ['last_used_at'];

    protected $appends = ['full_address'];


    /**
     * 关联模型
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }


    /**
     * 访问器
     */
    public function getFullAddressAttribute()
    {
        return "{$this->province}{$this->city}{$this->district}{$this->address}";
    }


    /**
     * 查询作用域
     */
    public function scopeOrderByUseTime($query)
    {
        return $query->orderBy('last_used_at', 'desc');
    }
}
